<?php
//require_once 'TVB/MSApi/Client/requires.php';
//require_once 'TVB/Logger/TVBLog.php';
//TVBLog::config("/data/logger/conf/config.xml");

require_once ( 'TVB/Entity/MemberFavourEntity.php' ) ;

$login_id = array_key_exists ('login_id', $_REQUEST)?$_REQUEST['login_id']:'guest';

$entity = new MemberFavourEntity($login_id) ;
$datetime = array_key_exists('datetime', $_REQUEST)?$_REQUEST['datetime']:time();
$url = array_key_exists ('url', $_REQUEST)?$_REQUEST['url']:'';
$video_title = array_key_exists('video_title', $_REQUEST)?$_REQUEST['video_title']:'';
$video_id = array_key_exists('video_id',$_REQUEST)?$_REQUEST['video_id']:'' ;
$programme_id = array_key_exists('programme_id', $_REQUEST)?$_REQUEST['programme_id']:'';

//echo $login_id.' '.$video_id;
$ret = $entity->selectByQuery("select count(*) cnt from favour where video_id = '".$video_id."'");
if ($ret[0]['cnt'] == 0){
	$entity_record = array ('datetime' => $datetime, 'url' => $url, 'video_title' => $video_title, 'video_id' => $video_id, 'programme_id' => $programme_id) ;
 
	$favour_entity = MemberFavourEntity::getInstance( $login_id ) ; 
	$favour_entity->insert( $entity_record );

	//echo json_encode(array('status'=>1));

	//$result = array ( 'status' => 1, 'description' => 'add favour success') ;
	//echo $_GET['jsonp_callback'] . '(' . json_encode($result) . ');';

	echo "Insert video ".$video_id." into ".$login_id." success!\n";
} else {
	echo "Video ".$video_id." already in favour of ".$login_id."!!!\n";
}
// add favour
?>
